import { createRouter, createWebHistory } from 'vue-router'
import routes from './modules'
import { createRouterGuard } from './guard'

// 创建路由实例
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  scrollBehavior: (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

// 应用路由守卫
createRouterGuard(router)

export default router